﻿var grid;
var varIncrementer = 0;
var v_TrnContractID = varIncrementer++,
     v_Sr = varIncrementer++,
     v_Action = varIncrementer++,
     v_ContractNo = varIncrementer++,
     v_Company = varIncrementer++,
     v_Client = varIncrementer++,
     v_Contract = varIncrementer++,
     v_PaymentMode = varIncrementer++,
     v_ContractStartDate = varIncrementer++,
     v_FinancialYear = varIncrementer++,
     v_ContractAmount = varIncrementer++;


$(document).ready(function () {
    $('#cboCompany').select2();
    $('#cboClient').select2();
    $('#cboContract').select2();
    $('#cboPaymentMode').select2();
    $('#cboStatus').select2();
    $('#cboFinancialYear').select2();
    $('#cboCompany').focus();
});

function ShowEditDiv(objControl) {
    var varRow = objControl.parentNode.parentNode;
    var varTitle = "Contract Details  # " + varRow.cells[v_ContractNo].innerText;
    $('#divShowDetails').dialog('open');
    $('#divShowDetails').dialog("option", "title", varTitle);
    document.getElementById('lblCompanyName').innerText = varRow.cells[v_Company].innerText;
    document.getElementById('lblClientName').innerText = varRow.cells[v_Client].innerText;
    document.getElementById('lblContractName').innerText = varRow.cells[v_Contract].innerText;

    var vAdditionalTrack = "RowID@@" + varRow.cells[v_Sr].innerText + "~~ContractID@@" + varRow.cells[v_TrnContractID].innerText;
    callBack('ViewDetails', '', vAdditionalTrack);
}


function fn_GetSearchResult(p_vTrack, p_objResult) {
    if (p_vTrack == "0") {
        callBack('GetSearchResult', 'cboCompany@cboClient@cboContract@cboPaymentMode@cboStatus@cboFinancialYear@txtContractStartDate@txtContractEndDate');
    }
    else {
        document.getElementById("divResult").innerHTML = p_objResult.grdResult;
    }
    return false;
}

/**** Regular Expression Validator *****/
function fn_RegExpValidator(p_obj, p_args) {
    p_args.IsValid = true;
    var varCntl = $("#" + p_obj.controltovalidate);
    if (varCntl.attr("type") == "text") {
        if (varCntl.val() != "") {
            var vValidation = fn_ValidateExpression(varCntl.val(), $(p_obj).attr("expressionid"));
            if (vValidation != "") {
                args.IsValid = false;
                sender.childNodes['0'].innerHTML = vValidation;
            }
        }
    }
    return p_args.IsValid;

    //var ServiceLineName = document.getElementById('txtServiceLineName').value;
    //if (ServiceLineName != '') {
    //    var strRet = fn_ValidateExpression(ServiceLineName, '5');

    //    if (strRet != '') {
    //        var span = document.getElementById("spnServiceLineName");
    //        span.textContent = strRet;
    //        $('#spnServiceLineName').show();
    //        p_args.IsValid = false;
    //    }
    //}

}

function getResponse(returnVal) {
    try {
        hideLoader(returnVal);
        var objResult = $.parseJSON(returnVal);
        if (objResult.SessionTimeOut == "1") {
            window.location.href = 'login.aspx';
        }
        else {
            var varTrack = objResult.Track;
            if (objResult.Track == "GetSearchResult") {
                fn_GetSearchResult("1", objResult);
            }
            else if (varTrack == "ViewDetails") {
                document.getElementById("divInvoiceDetails").innerHTML = objResult.grdInvoiceDetails;
                document.getElementById("divCollectionDetails").innerHTML = objResult.grdCollectionDetails;
            }
        }
    }
    catch (ex) {
        show_globalMessage('Error', 'error');
    }
}
